package com.hxkcloud.patient.photo;

import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.provider.MediaStore;

import java.util.ArrayList;
import java.util.Collections;

public class AlbumHelper
{
	public static ArrayList<MeenoPhotoEntity> getAllPhotos(Activity act)
	{
		ArrayList<MeenoPhotoEntity> galleryList = new ArrayList<MeenoPhotoEntity>();
		ContentResolver cr = act.getContentResolver();
		final String[] columns = { MediaStore.Images.Media.DATA,
				MediaStore.Images.Media._ID };
		final String orderBy = MediaStore.Images.Media._ID;
		Cursor imagecursor = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null, null, orderBy);
		if (imagecursor != null && imagecursor.getCount() > 0) 
		{
			while (imagecursor.moveToNext()) {
				MeenoPhotoEntity entity = new MeenoPhotoEntity();
				String item = new String();
				int dataColumnIndex = imagecursor
						.getColumnIndex(MediaStore.Images.Media.DATA);
				item = imagecursor.getString(dataColumnIndex);
				entity.setImagePath(item);
				entity.setSelected(false);
				galleryList.add(entity);
			}
		}
		Collections.reverse(galleryList);
		return galleryList;
	}
}
